'use strict';
module.exports = {
	/**
	 * 随机获取N条推荐
	 * @url client/article/pub/getSampleList 前端调用的url参数地址
	 * data 请求参数 说明
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let { _id, classify_id, page, pageSize } = data;

		let whereJson = {
			_id: _.nin([_id])
		};
		
		if(!vk.pubfn.isNull(classify_id)) {
			whereJson["classify_id"] = classify_id;
		}
		
		let dbName = "db-article";

		res["data"] = await vk.baseDao.selects({
			dbName,
			getMain: true,
			pageIndex: page || 1,
			pageSize: pageSize || 10,
			whereJson,
			fieldJson: {
				wx_openid: false
			},
			foreignDB: [
				{
					dbName:"uni-id-users",
					localKey:"uid",
					foreignKey:"_id",
					as:"userInfo",
					limit: 1 ,// limit>1则以数组形式返回
					fieldJson: {
						nickname: true,
						avatar: true
					}
				}
			]
		})
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
